﻿// <copyright file="HistoryEntry45.cs" company="Sinclair Community College">
// Copyright 2010 Sinclair Community College
// </copyright>
// <originalAuthor>Patrick S. Seymour (patrick.seymour@gmail.com)</originalAuthor>

namespace SinclairCC.AppV
{
    using System;

    /// <summary>
    /// This class represents a partial history entry in the CONT section of an App-V SFT file.
    /// </summary>
    /// <remarks>
    /// Because the layout of History Entry changed between versions 4.2 and 4.5 of App-V,
    /// packages created according to 4.5 specifications are not compatible with versions
    /// older than 4.5.
    /// This class represents the history entry from App-V version 4.5.
    /// </remarks>
    public class HistoryEntry45 : HistoryEntry
    {
        /// <summary>
        /// The byte length of the .NET version string, excluding the null terminator.
        /// </summary>
        private int dotNetVersionSize;

        /// <summary>
        /// The byte length of the Internet Explorer (IE) version string, excluding the null terminator.
        /// </summary>
        private int internetExplorerVersionSize;

        /// <summary>
        /// The byte length of the Media Player version string, excluding the null terminator.
        /// </summary>
        private int mediaPlayerVersionSize;

        /// <summary>
        /// The account name logged on under which the package was created.
        /// </summary>
        /// <remarks>
        /// This value is stored as a wide-char (double-byte) string without the terminating
        /// null character (0x0000) at the end.
        /// </remarks>
        private string accountName;

        /// <summary>
        /// The hostname of the machine under which the package was created.
        /// </summary>
        /// <remarks>
        /// This value is stored as a wide-char (double-byte) string without the terminating
        /// null character (0x0000) at the end.
        /// </remarks>
        private string hostName;

        /// <summary>
        /// The full path of the system directory on the operating system under which the package was created.
        /// </summary>
        /// <remarks>
        /// This value is stored as a wide-char (double-byte) string without the terminating
        /// null character (0x0000) at the end.
        /// </remarks>
        private string systemDirectoryPath;

        /// <summary>
        /// The full path of the Windows directory on the operating system under which the package was created.
        /// </summary>
        /// <remarks>
        /// This value is stored as a wide-char (double-byte) string without the terminating null character (0x0000) at the end.
        /// </remarks>
        private string windowsDirectoryPath;

        /// <summary>
        /// The full path of the user directory on the operating system under which the package was created.
        /// </summary>
        /// <remarks>
        /// This value is stored as a wide-char (double-byte) string without the terminating
        /// null character (0x0000) at the end.
        /// </remarks>
        private string userDirectoryPath;

        /// <summary>
        /// The version information for the Microsoft .NET Framework installed on the machine
        /// under which the package was created.
        /// </summary>
        /// <remarks>
        /// This value is stored as a wide-char (double-byte) string without the terminating
        /// null character (0x0000) at the end.
        /// </remarks>
        private string dotNetVersion;

        /// <summary>
        /// The version information for the Internet Explorer installed on the machine under
        /// which the package was created.
        /// </summary>
        /// <remarks>
        /// This value is stored as a wide-char (double-byte) string without the terminating
        /// null character (0x0000) at the end.
        /// </remarks>
        private string internetExplorerVersion;

        /// <summary>
        /// The version information for the Microsoft Windows Media Player installed on the
        /// machine under which the package was created.
        /// </summary>
        /// <remarks>
        /// This value is stored as a wide-char (double-byte) string without the terminating
        /// null character (0x0000) at the end.
        /// </remarks>
        private string mediaPlayerVersion;

        /// <summary>
        /// Initializes a new instance of the HistoryEntry45 class.
        /// </summary>
        /// <param name="fileReader">
        /// A binary file reader that points to the SFT file.
        /// </param>
        public HistoryEntry45(System.IO.BinaryReader fileReader)
            : base(fileReader)
        {
            this.dotNetVersionSize = fileReader.ReadInt32();
            this.internetExplorerVersionSize = fileReader.ReadInt32();
            this.mediaPlayerVersionSize = fileReader.ReadInt32();
            this.accountName = System.Text.Encoding.Unicode.GetString(fileReader.ReadBytes(this.SequencerAccountNameSize));
            this.hostName = System.Text.Encoding.Unicode.GetString(fileReader.ReadBytes(this.SequencerHostNameSize));
            this.systemDirectoryPath = System.Text.Encoding.Unicode.GetString(fileReader.ReadBytes(this.SequencerSystemDirectoryPathSize));
            this.windowsDirectoryPath = System.Text.Encoding.Unicode.GetString(fileReader.ReadBytes(this.SequencerWindowsDirectoryPathSize));
            this.userDirectoryPath = System.Text.Encoding.Unicode.GetString(fileReader.ReadBytes(this.SequencerUserDirectoryPathSize));
            this.dotNetVersion = System.Text.Encoding.Unicode.GetString(fileReader.ReadBytes(this.dotNetVersionSize));
            this.internetExplorerVersion = System.Text.Encoding.Unicode.GetString(fileReader.ReadBytes(this.internetExplorerVersionSize));
            this.mediaPlayerVersion = System.Text.Encoding.Unicode.GetString(fileReader.ReadBytes(this.mediaPlayerVersionSize));
        }

        /// <summary>
        /// Gets the hostname of the machine under which the package was created.
        /// </summary>
        public string SequencerHostName
        {
            get { return this.hostName; }
        }

        /// <summary>
        /// Gets the account name logged on under which the package was created.
        /// </summary>
        public string SequencerAccountName
        {
            get { return this.accountName; }
        }
        
        /// <summary>
        /// Gets the full path of the system directory on the operating system under which the package was created.
        /// </summary>
        public string SequencerSystemDirectoryPath
        {
            get { return this.systemDirectoryPath; }
        }

        /// <summary>
        /// Gets the full path of the Windows directory on the operating system under which the package was created.
        /// </summary>
        public string SequencerWindowsDirectoryPath
        {
            get { return this.windowsDirectoryPath; }
        }

        /// <summary>
        /// Gets the full path of the user directory on the operating system under which the package was created.
        /// </summary>
        public string SequencerUserDirectoryPath
        {
            get { return this.userDirectoryPath; }
        }

        /// <summary>
        /// Gets the version information for the Internet Explorer installed on the machine under
        /// which the package was created.
        /// </summary>
        public string SequencerInternetExplorerVersion
        {
            get { return this.internetExplorerVersion; }
        }

        /// <summary>
        /// Gets the version information for the Microsoft Windows Media Player installed on the
        /// machine under which the package was created.
        /// </summary>
        public string SequencerMediaPlayerVersion
        {
            get { return this.mediaPlayerVersion; }
        }

        /// <summary>
        /// Gets the version information for the Microsoft .NET Framework installed on the machine
        /// under which the package was created.
        /// </summary>
        public string SequencerDotNetVersion
        {
            get { return this.dotNetVersion; }
        }

        public override string ToString()
        {
            return string.Format("[{0:G}] {1} on {2}", this.ModifiedTimeStamp.ToLocalTime(), this.SequencerAccountName, this.SequencerHostName);
        }
    }
}
